package cn.com.taiji.pos.service.impl;

import cn.com.taiji.pos.entity.TradeConsumptionMain;
import cn.com.taiji.pos.mapper.TradeConsumptionMainMapper;
import cn.com.taiji.pos.service.ICardInfoService;
import cn.com.taiji.pos.service.ITradeConsumptionMainService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.dreamyoung.mprelation.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.List;

/**
 * <p>
 * 消费主单 服务实现类
 * </p>
 *
 * @author
 * @since 2021-03-01
 */
@Service
public class TradeConsumptionMainServiceImpl extends ServiceImpl<TradeConsumptionMainMapper, TradeConsumptionMain> implements ITradeConsumptionMainService {

    @Autowired
    private TradeConsumptionMainMapper tradeConsumptionMainMapper;
    @Autowired
    private ICardInfoService cardInfoService;

    @Override
    public List<TradeConsumptionMain> findByCustomerId(String customerId, String startTime, String endTime) {
        QueryWrapper<TradeConsumptionMain> tradeConsumptionMainWrapper = new QueryWrapper<>();
        tradeConsumptionMainWrapper.eq("CUSTOMER_ID", customerId);
        tradeConsumptionMainWrapper.between("CONSUMPTION_TIME", startTime, LocalDate.parse(endTime.split("T")[0]).plusDays(1));
        tradeConsumptionMainWrapper.orderByDesc("CONSUMPTION_TIME");
        return tradeConsumptionMainMapper.selectList(tradeConsumptionMainWrapper);
    }
}
